class Admin::AdvertsController < AdminController
  
  def index
    @adverts = Advert.all
  end
  
  def new
    @advert = Advert.new
  end
  
  def destroy
    @advert = Advert.find(params[:id])
    @advert.destroy
    flash_notice(:advert_removed)
    respond_to do |format|
      format.html { redirect_to(admin_adverts_url) }
      format.xml  { head :ok }
    end
  end
  
  
  def create
    @advert = Advert.new(params[:advert])
    @advert.user_id = @current_user.id
    if @advert.save
      flash_notice(:advert_created)
      redirect_to admin_adverts_url
    else 
      flash_notice(:advert_not_created)
      render :new
    end   
  end
  
  def show
    @advert = Advert.find(params[:id])
  end
  
  def edit
    @advert = Advert.find(params[:id])
  end
  
  def update
    @advert = Advert.find(params[:id])
    respond_to do |format|
      if @advert.update_attributes(params[:advert])
        flash_notice(:advert_updated)
        format.html { redirect_to admin_advert_url(@advert) }
        format.xml  { head :ok }
      else
        flash_error(:advert_not_updated)
        format.html { render :action => "edit" }
        format.xml  { render :xml => @advert.errors, :status => :unprocessable_entity }
      end
    end
    
  end
  
  
  
  
end
